package com.uchiha.nova.mainService.wrapper;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.uchiha.nova.core.model.entity.ChinaAreaEntity;
import com.uchiha.nova.core.model.vo.ChinaAreaVO;
import com.uchiha.nova.core.tool.support.BaseEntityWrapper;
import com.uchiha.nova.core.tool.node.ForestNodeMerger;
import com.uchiha.nova.core.model.entity.ChinaOrgCodeEntity;
import com.uchiha.nova.core.model.vo.ChinaOrgCodeVO;
import com.uchiha.nova.mainService.service.IChinaOrgCodeService;
import com.uchiha.nova.core.tool.util.SpringUtil;

import java.util.List;
import java.util.stream.Collectors;
/**
 * 中国区域机构代码 包装类,返回视图层所需的字段
 *
 * @author Uchihashiamu
 */
public class ChinaOrgCodeWrapper extends BaseEntityWrapper<ChinaOrgCodeEntity, ChinaOrgCodeVO>  {
  
  IChinaOrgCodeService chinaOrgCodeService = SpringUtil.getBean(IChinaOrgCodeService.class);
  
	public static ChinaOrgCodeWrapper build() {
		return new ChinaOrgCodeWrapper();
 	}

	@Override
	public ChinaOrgCodeVO entityVO(ChinaOrgCodeEntity chinaOrgCodeEntity) {
		ChinaOrgCodeVO chinaOrgCodeVO = new ChinaOrgCodeVO();
		BeanUtil.copyProperties(chinaOrgCodeEntity, chinaOrgCodeVO);

		return chinaOrgCodeVO;
	}
	public List<ChinaOrgCodeVO> listVO(List<ChinaOrgCodeEntity> list) {
		List<ChinaOrgCodeVO> collect = list.stream().map(item -> {
            ChinaOrgCodeVO chinaOrgCodeVO = new ChinaOrgCodeVO();
		    BeanUtil.copyProperties(item, chinaOrgCodeVO);			
			return chinaOrgCodeVO;
		}).collect(Collectors.toList());
		return collect;
    // return ForestNodeMerger.merge(collect);
	}
  
  	@Override
	public IPage<ChinaOrgCodeVO> pageVO(IPage<ChinaOrgCodeEntity> pages) {
		IPage<ChinaOrgCodeVO> page = pages.convert(item->{
            ChinaOrgCodeVO chinaOrgCodeVO = new ChinaOrgCodeVO();
		    BeanUtil.copyProperties(item, chinaOrgCodeVO);			
			return chinaOrgCodeVO;
		});
		return page;
	}

	public List<ChinaOrgCodeVO> listNodeVO(List<ChinaOrgCodeEntity> list) {
		List<ChinaOrgCodeVO> collect = list.stream().map(dict -> {
			ChinaOrgCodeVO vo = new ChinaOrgCodeVO();
			BeanUtil.copyProperties(dict,vo);

			return vo;
		}).collect(Collectors.toList());
		return ForestNodeMerger.merge(collect);
	}
}
